package com.zhaoxi.project.fms.controller;

import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.framework.web.page.TableDataInfo;
import com.zhaoxi.project.fms.domain.FmsClassification;
import com.zhaoxi.project.fms.service.impl.FmsClassificationServiceImpl;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 记账科目Controller
 *
 * @author zhaoxi
 * @date 2023-12-30
 */
@RestController
@RequestMapping("/fms/classification")
public class FmsClassificationController extends BaseService
{
    @Autowired
    private FmsClassificationServiceImpl fmsClassificationService;

    /**
     * 分页查询记账科目列表
     */
    @PreAuthorize("@ss.hasPermi('fms:classification:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsClassification fmsClassification)
    {
        startPage();
        List<FmsClassification> list = fmsClassificationService.selectFmsClassificationList(fmsClassification);
        return getDataTable(list);
    }
    

    /**
     * 导出记账科目列表
     */
    @PreAuthorize("@ss.hasPermi('fms:classification:export')")
    @Log(title = "记账科目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsClassification fmsClassification)
    {
        List<FmsClassification> list = fmsClassificationService.selectFmsClassificationList(fmsClassification);
        ExcelUtil<FmsClassification> util = new ExcelUtil<FmsClassification>(FmsClassification.class);
        util.exportExcel(response, list, "记账科目数据");
    }

    /**
     * 获取记账科目详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:classification:query')")
    @GetMapping(value = "/{code}")
    public PageData getInfo(@PathVariable("code") String code)
    {
        return success(fmsClassificationService.selectFmsClassificationByCode(code));
    }

    /**
     * 新增记账科目
     */
    @PreAuthorize("@ss.hasPermi('fms:classification:add')")
    @Log(title = "记账科目", businessType = BusinessType.INSERT)
    @PostMapping
    public PageData add(@RequestBody FmsClassification fmsClassification) {
        fmsClassification.setCreateBy(this.getUsername());
        return toAjax(fmsClassificationService.insertFmsClassification(fmsClassification));
    }

    /**
     * 修改记账科目
     */
    @PreAuthorize("@ss.hasPermi('fms:classification:edit')")
    @Log(title = "记账科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public PageData edit(@RequestBody FmsClassification FmsClassification)
    {
        return toAjax(fmsClassificationService.updateFmsClassification(FmsClassification));
    }
    

    /**
     * 删除记账科目
     */
    @PreAuthorize("@ss.hasPermi('fms:classification:remove')")
    @Log(title = "记账科目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public PageData remove(@PathVariable String[] codes)
    {
        return toAjax(fmsClassificationService.deleteFmsClassificationByCodes(codes));
    }
}
